// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Twinkle Stars Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// The script path uses "Tinkle" but the object name is "Twinkle", we're sticking with the latter for names here

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer
private alias object.value1 : object.tablePos

// ========================
// Tables
// ========================

private table TwinkleStars_starPosTable
	-31, -72
	-69,   2
	 81,   8
	 19,  65
	127, -78
	-95, -13
	 97, -16
	-18,  75
	 95, -69
	 70,  23
end table


// ========================
// Events
// ========================

event ObjectUpdate
	if object.timer == 0
		object.frame = 0
		if object.tablePos < 20
			GetTableValue(object.xpos, object.tablePos, TwinkleStars_starPosTable)
			object.tablePos++

			GetTableValue(object.ypos, object.tablePos, TwinkleStars_starPosTable)
			object.tablePos++

			object.timer++
			PlaySfx(SfxName[Twinkle], false)
		else
			ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)
		end if
	else
		object.frame = object.timer
		object.frame >>= 1
		object.timer++
		object.timer &= 15
	end if
end event


event ObjectDraw
	if object.frame < 6
		if object.timer < 11
			temp0 = screen.xcenter
			temp0 += object.xpos
			temp1 = screen.ycenter
			temp1 += object.ypos
			DrawSpriteScreenXY(object.frame, temp0, temp1)
		end if
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Title/Title.gif")
	
	// Twinkle Sparkle Frames
	SpriteFrame(-4, -4, 7, 7, 417, 59)
	SpriteFrame(-8, -8, 15, 15, 425, 51)
	SpriteFrame(-12, -12, 23, 23, 441, 43)
	SpriteFrame(-8, -8, 15, 15, 425, 51)
	SpriteFrame(-4, -4, 7, 7, 417, 59)
	SpriteFrame(-4, -4, 7, 7, 417, 59)
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Title/Title.gif")
	SpriteFrame(-12, -12, 23, 23, 441, 43)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
